const maxSlidingWindow = (nums: Array<number>, k: number) => {
  // 缓存数组的长度
  const len = nums.length;
  // 定义结果数组
  const res:Array<number> = [];
  // 定义左右指针
  let left = 0,
    right = k - 1;
  // 开始循环
  while (right < len) {
    // 计算当前窗口内的最大值
    const max = calMax(nums, left, right);
    if (max) res.push(max);
    left++;
    right++;
  }
  return res;
};
const calMax = (nums: Array<number>, left: number, right: number) => {
  // 处理数组为空的边界情况
  if (!nums || !nums.length) return;
  //
  let maxNum = nums[left];
  for (let index = left; index <= right; index++) {
    if (nums[index] > maxNum) maxNum = nums[index];
  }
  // 返回最大值
  return maxNum;
};
